package dl.bukkit.myststus.vexshow.sub.dynamic;

import dl.bukkit.myststus.vexshow.AbstractVexHud;
import dl.bukkit.myststus.vexshow.Attribute;
import lk.vexview.hud.VexShow;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;

public abstract class DynamicHandler extends AbstractVexHud {

    public static final String DIRECTION = "direction";

    private final String direction;

    public DynamicHandler(String key, YamlConfiguration yaml) {
        super(key, yaml);
        this.direction = yaml.getString(DIRECTION);
        addConfigDebug(DIRECTION, direction);
    }

    public final VexShow getDynamicValue(Player player, Entity entity) {
        int x = getX(player);
        int y = getY(player);
        int h = getH();
        int w = getW();
        switch (direction.toUpperCase()) {
            case "TOP":
                h = getValue(player, entity, h);
                break;
            case "BOTTOM":
                y = y + (h - getValue(player, entity, h));
                h = getValue(player, entity, h);
                break;
            case "RIGHT":
                w = getValue(player, entity, w);
                break;
            case "LEFT":
                x = x + (w - getValue(player, entity, w));
                w = getValue(player, entity, w);
        }
        return getVexShow(player, x, y, w, h);
    }

    public abstract double getScale(Player player, Entity entity);

    public int getValue(Player player, Entity entity, int value) {
        return Attribute.toRounding(value * getScale(player, entity));
    }
}
